fix(client): always force WS reconnect on iOS foreground return#367
Merged
Conversation
iOS kills WebSocket connections during background without updating readyState. checkAndReconnect() previously trusted readyState, so if the socket appeared OPEN the function did nothing — first message sent on the dead socket was silently lost. Remove the readyState guard: always tear down the old socket and create a fresh connection. Sends during the reconnect window queue in pendingSends and flush after the welcome handshake completes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
Author
Centaur ReviewFound 4 issue(s) (2 warning).
|
4 tasks
dimakis
added a commit
that referenced
this pull request
Jun 5, 2026
* fix(client): always force WS reconnect on iOS foreground return (#367) iOS kills WebSocket connections during background without updating readyState. checkAndReconnect() previously trusted readyState, so if the socket appeared OPEN the function did nothing — first message sent on the dead socket was silently lost. Remove the readyState guard: always tear down the old socket and create a fresh connection. Sends during the reconnect window queue in pendingSends and flush after the welcome handshake completes. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> * fix: address Centaur review — platform guard, socket leak, tests - Add force parameter to checkAndReconnect(): iOS (via forceReconnect) always forces, desktop browser visibility events use default (false) which preserves healthy sockets - Close old socket in defuseOldWs() to prevent server-side connection leak from orphaned live sockets - Add 6 tests covering: force vs default behavior, reconnectTimer guard, pending send flush after forced reconnect, socket close Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
readyStatecheckAndReconnect()trustedreadyState— if the socket appeared OPEN, it did nothingpendingSendsand flush after the welcome handshakeThis is a regression — previously both messages reached the agent (even if a double-send was needed to wake it up). Now the first message is silently dropped into a dead socket.
Root cause
connection.ts:328-336— thereadyState !== OPENguard:iOS kills the TCP connection during background but the JS
readyStateproperty staysOPENuntil a send/recv actually fails. The heartbeat (5s interval) also checksreadyState !== OPEN, so it has the same blind spot. The first user message fires into the void.Test plan
🤖 Generated with Claude Code